def bubble_sort(array, reverse=False):
    swap_num = 0
    for i in range(len(array)):
        for j in range(len(array) - i - 1):
            if array[j] > array[j + 1]:
                array[j], array[j + 1] = array[j + 1], array[j]
                swap_num += 1
        print(f'第{i}轮循环后', array)
    if reverse:
        array.reverse()
    return swap_num


if __name__ == '__main__':
    str_array = input()
    if str_array.isdigit:
        my_array = list(map(int, str_array.split()))
        print('交换次数:', bubble_sort(my_array))
        print(my_array)
    else:
        print('错误输入')
